import { getBaseURL, get, post, deletes } from "./request";

const HttpManager = {
  // 获取图片信息
  attachImageUrl: (url) => url ? `${getBaseURL()}/${url}` : "https://cube.elemecdn.com/e/fd/0fc7d20532fdaf769a25683617711png.png",
  // =======================> 用户 API 完成
  // 登录
  signIn: ({username,password}) => post(`user/loginByPassword`, {username,password}),
  signInByemail: ({email,password})=>post(`user/loginByEmail`, {email,password}),
  // 注册
  SignUp: ({username,password,sex,phoneNum,email,birth,introduction,location}) => post(`user/insert`, {username,password,sex,phoneNum,email,birth,introduction,location}),
  // 删除用户
  deleteUser: (id) => get(`user/deleteById?id=${id}`),
  // 更新用户信息
  updateUserMsg: ({id,username,sex,phoneNum,email,birthday,introduction,location}) => post(`user/updateInfo`, {id,username,sex,phoneNum,email,birthday,introduction,location}),
  updateUserPassword: ({id,username,oldPassword,password}) => post(`user/updatePassword`, {id,username,oldPassword,password}),
  // 返回指定ID的用户
  getUserOfId: (id) => get(`user/selectById?id=${id}`),
  // 更新用户头像
  uploadUrl: (userId) => `${getBaseURL()}/user/updateUserImage?id=${userId}`,

  // =======================> 歌单 API 完成
  // 获取全部歌单
  getSongList: () => get("songList/allSongList"),
  // 获取歌单类型
  getSongListOfStyle: (style) => get(`songList/orderByStyle?style=${style}`),
  // 返回标题包含文字的歌单
  getSongListOfLikeTitle: (keywords) => get(`songList/selectByLikeTitle?title=${keywords}`),
  // 返回歌单里指定歌单ID的歌曲
  getListSongOfSongId: (id) => get(`listSong/selectSongListId?id=${id}`),

  // =======================> 歌手 API  完成
  // 返回所有歌手
  getAllSinger: () => get("singer/selectAllSinger"),
  // 通过性别对歌手分类
  getSingerOfSex: (sex) => get(`singer/selectSingerBySex?sex=${sex}`),

  // =======================> 收藏 API 完成
  // 返回的指定用户ID的收藏列表
  getCollectionOfUser: (userId) => get(`collect/selectByUserId?userId=${userId}`),
  // 添加收藏的歌曲 type: 0 代表歌曲， 1 代表歌单
  setCollection: ({userId,type,songId}) => post(`collect/insert`,{userId,type,songId}),

  deleteCollection: (userId, songId) => deletes(`collect/delete?userId=${userId}&&songId=${songId}`),

  isCollection: ({userId, type, songId}) => post(`collect/isCollected`, {userId, type, songId}),

  // =======================> 评分 API 完成
  // 提交评分
  setRank: ({songListId,userId,score}) => post(`level/insert`, {songListId,userId,score}),
  // 获取指定歌单的评分
  getRankOfSongListId: (songListId) => get(`level/selectAvgBySongListId?songListId=${songListId}`),
  // 获取指定用户的歌单评分
  getUserRank: (userId, songListId) => get(`level/selectScore?userId=${userId}&songListId=${songListId}`),

  // =======================> 评论 API 完成
  // 添加评论
  setComment: ({userId,content,songId,songListId,nowType}) => post(`comment/insert`, {userId,content,songId,songListId,nowType}),
  // 删除评论
  deleteComment: (id) => get(`comment/delete?id=${id}`),
  // 点赞
  setSupport: ({id,up}) => post(`comment/praise`, {id,up}),
  // 返回所有评论
  getAllComment: (type, id) => {
    let url = "";
    if (type === 1) {
      url = `comment/selectBySongListId?songListId=${id}`;
    } else if (type === 0) {
      url = `comment/selectBySongId?songId=${id}`;
    }
    return get(url);
  },

  // =======================> 歌曲 API
  // 返回指定歌曲ID的歌曲
  getSongOfId: (songId) => get(`song/selectById?id=${songId}`),
  // 返回指定歌手ID的歌曲
  getSongOfSingerId: (id) => get(`song/selectBySingerId?singerId=${id}`),
  // 返回指定歌手名的歌曲
  getSongOfSingerName: (name) => get(`song/selectByLikeName?name=${name}`),
  // 下载音乐
  downloadMusic: (url) => get(url, { responseType: "blob" }),

  //======================> 点赞api的优化 避免有些是重复的点赞！新增数据表了得

  insertOrDeleteUp:({commentId,userId}) => post(`userUp/insertOrDeleteUp`, {commentId,userId}),


  //获取所有的海报
  getBannerList: () => get("banner/selectAll")
};



export { HttpManager };
